// 教室类型定义
export interface Classroom {
  id: number;
  name: string;
  location: string;
  capacity: number;
  type: string;
  equipment: string;
  available: boolean;
}

// mock数据
export const mockClassroomData: Classroom[] = [
  {
    id: 1,
    name: '101教室',
    location: '教学楼1楼',
    capacity: 40,
    type: '普通教室',
    equipment: '投影仪',
    available: true
  },
  {
    id: 2,
    name: '201教室',
    location: '教学楼2楼',
    capacity: 60,
    type: '多媒体教室',
    equipment: '投影仪、音响、电脑',
    available: true
  },
  {
    id: 3,
    name: '301实验室',
    location: '实验楼3楼',
    capacity: 30,
    type: '实验室',
    equipment: '计算机、网络设备',
    available: false
  },
  {
    id: 4,
    name: '401阶梯教室',
    location: '教学楼4楼',
    capacity: 120,
    type: '阶梯教室',
    equipment: '投影仪、音响、麦克风',
    available: true
  },
  {
    id: 5,
    name: '501会议室',
    location: '行政楼5楼',
    capacity: 20,
    type: '会议室',
    equipment: '投影仪、白板',
    available: false
  },
  {
    id: 6,
    name: '601教室',
    location: '教学楼6楼',
    capacity: 40,
    type: '普通教室',
    equipment: '投影仪',
    available: true
  },
  {
    id: 7,
    name: '701教室',
    location: '教学楼7楼',
    capacity: 40,
    type: '普通教室',
    equipment: '投影仪',
    available: true
  },
  {
    id: 8,
    name: '801教室',
    location: '教学楼8楼',
    capacity: 40,
    type: '普通教室',
    equipment: '投影仪',
    available: true
  },
  {
    id: 9,
    name: '901教室',
    location: '教学楼9楼',
    capacity: 40,
    type: '普通教室',
    equipment: '投影仪',
    available: true
  },
  {
    id: 10,
    name: '1001教室',
    location: '教学楼10楼',
    capacity: 40,
    type: '普通教室',
    equipment: '投影仪',
    available: true
  },



];

// 模拟API调用获取教室数据
export const getClassrooms = async (): Promise<Classroom[]> => {
  // 模拟网络延迟
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(mockClassroomData);
    }, 300);
  });
};

// 模拟API调用添加教室
export const addClassroom = async (classroom: Omit<Classroom, 'id'>): Promise<Classroom> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      const newClassroom: Classroom = {
        ...classroom,
        id: mockClassroomData.length + 1
      };
      mockClassroomData.push(newClassroom);
      resolve(newClassroom);
    }, 300);
  });
};

// 模拟API调用更新教室
export const updateClassroom = async (id: number, classroom: Partial<Classroom>): Promise<Classroom> => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      const index = mockClassroomData.findIndex(item => item.id === id);
      if (index === -1) {
        reject(new Error('教室不存在'));
        return;
      }
      mockClassroomData[index] = {
        ...mockClassroomData[index],
        ...classroom
      };
      resolve(mockClassroomData[index]);
    }, 300);
  });
};

// 模拟API调用删除教室
export const deleteClassroom = async (id: number): Promise<boolean> => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      const index = mockClassroomData.findIndex(item => item.id === id);
      if (index === -1) {
        reject(new Error('教室不存在'));
        return;
      }
      mockClassroomData.splice(index, 1);
      resolve(true);
    }, 300);
  });
};